package com.itheima.server.service;

import com.itheima.domain.db.User;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @author 阿鹏
 * @date 2021/1/31 20:13
 */
@Service
public class CacheTestService {

    @Cacheable(cacheNames = "users",key = "#userId") // 设置缓存
    public User findById(long userId) {
        System.out.println("findById,查询数据库");
        User user = new User();
        user.setId(userId);
        user.setMobile("12200122000");
        return user;
    }

    @CacheEvict(cacheNames = "users", key = "#userId") // 关闭缓存
    public void update(long userId) {
        System.out.println("update...");
    }
}
